﻿using MySql.Data.MySqlClient;

using NewChillers.Helpers;
using NewChillers.Models;
using NewChillers.Models.Events;
using NewChillers.Utils;
using NewChillers.Views;

using OfficeOpenXml;

using System;
using System.Data;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Input;

namespace NewChillers.ViewModels
{
    public class AlarmViewModel : ObservableObject
    {

        #region 属性
        private UserModel _currentUser;
        private readonly ShellViewModel _shellViewModel;
        private bool _isChecked1; // ToggleButton 状态 监测是否启动
        //private bool _isChecked2; // ToggleButton 状态 列表是否显示历史记录
        private string _toggleText1 = "监测已关闭";
        //private string _toggleText2 = "历史记录:隐藏";
        private List<AlarmModel> _alarmList; // 报警列表
        private bool _isAlarmListLoading; // 是否加载中
        private DateTime? _startTime; // 开始时间
        private DateTime? _endTime; // 截止时间
        private string _alarmMessage;// 报警信息
        private string _selcectBtnContent; //查询按钮内容
        private CancellationTokenSource _monitoringCancellationTokenSource; // 监控取消令牌
        private AlarmParameterModel _alarmParameters; // 报警参数模型


        public bool IsChecked1
        {
            get => _isChecked1;
            set
            {
                ToggleText1 = value ? "监测已开启" : "监测已关闭";
                SetProperty(ref _isChecked1, value);
                // 当监测状态改变时，启动或停止监控
                ToggleMonitoring(value);
            }
        }


        public string AlarmMessage
        {
            get => _alarmMessage;
            set => SetProperty(ref _alarmMessage, value);
        }
        public string ToggleText1
        {
            get => _toggleText1;
            set => SetProperty(ref _toggleText1, value);
        }
        public List<AlarmModel> AlarmList
        {
            get => _alarmList;
            set => SetProperty(ref _alarmList, value);
        }
        public bool IsAlarmListLoading
        {
            get => _isAlarmListLoading;
            set => SetProperty(ref _isAlarmListLoading, value);
        }
        public DateTime? StartTime
        {
            get => _startTime;
            set => SetProperty(ref _startTime, value);
        }
        public DateTime? EndTime
        {
            get => _endTime;
            set => SetProperty(ref _endTime, value);
        }

        public string SelcectBtnContent
        {
            get => _selcectBtnContent;
            set => SetProperty(ref _selcectBtnContent, value);
        }

        public ICommand RefreshCommand { get; } // 刷新
        public ICommand SearchCommand { get; } // 查询
        public ICommand EditCommand { get; } // 修改报警参数
        public ICommand ExportCommand { get; } // 导出
        public ICommand CopyCommand { get; } // 复制
        //public ICommand StartMonitorCommand { get; } // 启动监控
        //public ICommand StopMonitorCommand { get; } // 停止监控

        #endregion

        public AlarmViewModel(UserModel userModel, ShellViewModel shellViewModel)
        {

            SelcectBtnContent = "查询历史报警记录";

            _currentUser = userModel;
            _shellViewModel = shellViewModel;

            IsChecked1 = false;

            InitAlarmList();

            RefreshCommand = new RelayCommand(ExecuteRefresh);
            SearchCommand = new RelayCommand(ExecuteSearch);
            EditCommand = new RelayCommand(ExecuteEdit);
            //StartMonitorCommand = new RelayCommand(ExecuteStartMonitor);
            //StopMonitorCommand = new RelayCommand(ExecuteStopMonitor);
            ExportCommand = new RelayCommand(ExecuteExport);

            CopyCommand = new RelayCommand<AlarmModel>(ExecuteCopy);

            // 订阅
            _shellViewModel.UserInfoUpdate += OnUserInfoUpdate;
        }

        #region 查询
        /// <summary>
        /// 初始化报警列表
        /// </summary>
        private void InitAlarmList()
        {
            LoadAlarmList(0); // 0 表示当前报警
        }

        /// <summary>
        /// 获取历史报警列表
        /// </summary>
        private void GetHistoryAlarmList()
        {
            LoadAlarmList(1); // 1 表示历史报警
        }

        /// <summary>
        /// 加载报警列表通用方法
        /// </summary>
        /// <param name="alarmStatus">报警状态 0-当前报警 1-历史报警</param>
        private void LoadAlarmList(int alarmStatus)
        {
            // 防止重复加载
            if (IsAlarmListLoading)
                return;

            IsAlarmListLoading = true;

            try
            {
                List<MySqlParameter> parameters = new List<MySqlParameter>();

                string sql = @"SELECT * FROM alarm_info WHERE 1 = 1";

                if (StartTime != null)
                {
                    sql += " AND alarm_create_time >= @StartTime";
                    parameters.Add(new MySqlParameter("@StartTime", StartTime.Value.Date));
                }
                if (EndTime != null)
                {
                    sql += " AND alarm_create_time <= @EndTime";
                    parameters.Add(new MySqlParameter("@EndTime", EndTime.Value.Date.AddDays(1).AddTicks(-1)));
                }

                sql += " AND alarm_status = @AlarmStatus ORDER BY alarm_id DESC";
                parameters.Add(new MySqlParameter("@AlarmStatus", alarmStatus));

                Func<IDataRecord, AlarmModel> mapper = reader => new AlarmModel
                {
                    AlarmId = Convert.ToInt32(reader["alarm_id"]),
                    AlarmMessage = reader["alarm_message"].ToString(),
                    AlarmType = reader["alarm_type"].ToString(),
                    AlarmSetValue = reader["alarm_set_value"].ToString(),
                    AlarmRealValue = reader["alarm_real_value"].ToString(),
                    AlarmCreateTime = Convert.ToDateTime(reader["alarm_create_time"]),
                    AlarmRecoveryTime = Convert.IsDBNull(reader["alarm_recovery_time"])
                    ? null
                    : Convert.ToDateTime(reader["alarm_recovery_time"])
                };

                AlarmList = MysqlHelper.ExecuteQuery<AlarmModel>(sql, mapper, parameters.ToArray());
            }
            catch (Exception ex)
            {
                LogHelper.Error(this.GetType(), "[加载报警]|" + "报警列表加载失败", ex, _currentUser.UserAccount);
                MessageBox.Show("报警列表加载失败" + ex);
                AlarmList = new List<AlarmModel>();
            }
            finally
            {
                IsAlarmListLoading = false;
            }
        }

        /// <summary>
        /// 查询
        /// </summary>
        private async void ExecuteSearch(object obj)
        {
            InitAlarmList(); if (SelcectBtnContent == "查询历史报警记录")
            {
                // 当前显示的是"查询历史报警记录"，点击后应加载历史报警并改变按钮文字
                GetHistoryAlarmList();
                SelcectBtnContent = "查询正在报警记录";
            }
            else
            {
                // 当前显示的是"查询正在报警记录"，点击后应加载正在报警并改变按钮文字
                InitAlarmList();
                SelcectBtnContent = "查询历史报警记录";
            }
        }

        /// <summary>
        /// 刷新
        /// </summary>
        private async void ExecuteRefresh(object obj)
        {
            StartTime = null;
            EndTime = null;

            // 根据当前按钮文字决定刷新哪种报警列表
            if (SelcectBtnContent == "查询正在报警记录")
            {
                GetHistoryAlarmList();
            }
            else
            {
                InitAlarmList();
            }
        }
        #endregion

        #region 设置报警参数
        private void ExecuteEdit(object obj)
        {
            // 跳转到设置报警参数页面

            try
            {

                // 检查用户是否有修改权限
                if (_currentUser.UserIdentity == 1)
                {
                    MsgBoxHelper.Warning("您没有权限修改报警参数");
                    return;
                }

                // 打开报警参数设置窗口
                AlarmParameterSettingPage settingPage = new AlarmParameterSettingPage(_currentUser);
                var result = settingPage.ShowDialog();

                if (result == true)
                {
                    // 如果设置成功，可以刷新报警列表
                    //InitAlarmList();
                    MsgBoxHelper.Info("报警参数设置成功");
                }

            }
            catch (Exception ex)
            {
                MsgBoxHelper.Error($"打开报警参数设置失败: {ex.Message}");
                LogHelper.Error(this.GetType(), "[修改报警参数]|" + "打开报警参数设置失败", ex, _currentUser.UserAccount);
            }
        }
        #endregion

        #region 更新当前登录用户的信息 事件处理
        /// <summary>
        /// 接收到通知
        /// </summary>
        private void OnUserInfoUpdate(object sender, UserInfoUpdateEventArgs e)
        {
            // 空值检查，避免NullReferenceException
            if (e?.UpdatedUser != null)
            {
                _currentUser = e.UpdatedUser;
                Debug.WriteLine("Alarm页面|用户信息已更新");
            }
            else
            {
                Debug.WriteLine("收到空的事件参数");
            }
        }

        /// <summary>
        /// 析构函数中的事件取消订阅
        /// </summary>
        ~AlarmViewModel()
        {
            _shellViewModel.UserInfoUpdate -= OnUserInfoUpdate;
            // 停止监控并清理资源
            _monitoringCancellationTokenSource?.Cancel();
            _monitoringCancellationTokenSource?.Dispose();
        }
        #endregion

        #region 操作
        /// <summary>
        /// 复制单条警报
        /// </summary>
        private void ExecuteCopy(AlarmModel alarm)
        {
            if (alarm == null)
                return;

            try
            {
                // 构建要复制的文本内容
                string alarmContent = FormatLogContent(alarm);

                // 复制到剪贴板
                Clipboard.SetText(alarmContent);

                // 显示成功消息
                MsgBoxHelper.Info("报警内容已复制到剪贴板");

                // 记录操作日志
                LogHelper.Info(this.GetType(), $"[复制报警]|" + $"复制报警记录 ID:{alarm.AlarmId}", _currentUser.UserAccount);
            }
            catch (Exception ex)
            {
                MsgBoxHelper.Error($"复制失败: {ex.Message}");
                LogHelper.Error(this.GetType(), "[复制报警]|" + "复制报警内容失败", ex, _currentUser.UserAccount);
            }
        }
        /// <summary>
        /// 格式化警报内容
        /// </summary>
        private string FormatLogContent(AlarmModel alarm)
        {
            var analarm = new StringBuilder();
            analarm.AppendLine($"ID: {alarm.AlarmId}");
            analarm.AppendLine($"报警类型: {alarm.AlarmType}");
            analarm.AppendLine($"报警设定值: {alarm.AlarmSetValue}");
            analarm.AppendLine($"报警实际值: {alarm.AlarmRealValue}");
            //analarm.AppendLine($"报警级别: {alarm.AlarmRate}");
            analarm.AppendLine($"报警产生时间: {alarm.AlarmCreateTime:yyyy-MM-dd HH:mm:ss}");
            analarm.AppendLine($"报警恢复时间: {alarm.AlarmRecoveryTime:yyyy-MM-dd HH:mm:ss}");
            return analarm.ToString();
        }
        #endregion

        #region 监控

        /// <summary>
        /// 控制监控状态
        /// </summary>
        private void ToggleMonitoring(bool start)
        {
            if (start)
            {
                // 启动监控
                _monitoringCancellationTokenSource = new CancellationTokenSource();
                // 初始化报警参数模型
                _alarmParameters = new AlarmParameterModel();
                // 启动异步监控任务
                Task.Run(async () => await MonitoringAsync(_monitoringCancellationTokenSource.Token));
            }
            else
            {
                // 停止监控
                _monitoringCancellationTokenSource?.Cancel();
            }
        }

        /// <summary>
        /// 启动监控
        /// </summary>
        //private void ExecuteStartMonitor(object obj)
        //{
        //    try
        //    {
        //        IsChecked1 = true;
        //    }
        //    catch (Exception ex)
        //    {
        //        //MsgBoxHelper.Error($"启动报警监控失败: {ex.Message}");
        //        LogHelper.Error(this.GetType(), "[启动监控]|启动报警监控失败", ex, _currentUser.UserAccount);
        //    }
        //}

        /// <summary>
        /// 停止监控
        /// </summary>
        //private void ExecuteStopMonitor(object obj)
        //{
        //    try
        //    {
        //        IsChecked1 = false;
        //    }
        //    catch (Exception ex)
        //    {
        //        MsgBoxHelper.Error($"停止报警监控失败: {ex.Message}");
        //        LogHelper.Error(this.GetType(), "[停止监控]|停止报警监控失败", ex, _currentUser.UserAccount);
        //    }
        //}

        /// <summary>
        /// 监测进程
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        private async Task MonitoringAsync(CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                try
                {
                    // 重新加载报警参数（支持动态更新）
                    _alarmParameters.LoadFromConfig();

                    // 获取实时数据并检查报警
                    await CheckRealTimeDataAndAlarmsAsync();

                    // 等待一段时间后继续监控
                    await Task.Delay(10000, cancellationToken); // 10秒检查一次
                }
                catch (OperationCanceledException)
                {
                    // 正常取消
                    break;
                }
                catch (Exception ex)
                {
                    LogHelper.Error(this.GetType(), "[监控循环]|监控过程中发生错误", ex, _currentUser?.UserAccount);
                    await Task.Delay(5000, cancellationToken); // 出错后等待5秒再继续
                }
            }
        }

        /// <summary>
        /// 检查实时数据并触发报警
        /// </summary>
        /// <returns></returns>
        private async Task CheckRealTimeDataAndAlarmsAsync()
        {
            try
            {
                // 这里需要根据你的实际数据源来获取实时数据
                // 示例：假设你有以下方法获取实时数据
                double currentPressure = await GetCurrentPressureAsync();
                double currentTemperature = await GetCurrentTemperatureAsync();
                double currentFlow = await GetCurrentFlowAsync();

                DateTime currentTime = DateTime.Now;

                // 检查并处理各种报警
                await CheckAndHandleAlarmAsync("压力", currentPressure, _alarmParameters.HighPressure, _alarmParameters.LowPressure, "MPa");
                await CheckAndHandleAlarmAsync("温度", currentTemperature, _alarmParameters.HighTemperature, _alarmParameters.LowTemperature, "℃");
                await CheckAndHandleAlarmAsync("流量", currentFlow, _alarmParameters.HighFlow, _alarmParameters.LowFlow, "m³/h");
            }
            catch (Exception ex)
            {
                LogHelper.Error(this.GetType(), "[检查数据]|检查实时数据时发生错误", ex, _currentUser?.UserAccount);
            }
        }

        /// <summary>
        /// 检查并处理单个报警
        /// </summary>
        /// <param name="alarmType"></param>
        /// <param name="currentValue"></param>
        /// <param name="highLimit"></param>
        /// <param name="lowLimit"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        private async Task CheckAndHandleAlarmAsync(string alarmType, double currentValue, double highLimit, double lowLimit, string unit)
        {
            string alarmMessage = "";
            bool shouldAlarm = false;

            if (currentValue > highLimit)
            {
                alarmMessage = $"{alarmType}过高";
                shouldAlarm = true;
            }
            else if (currentValue < lowLimit)
            {
                alarmMessage = $"{alarmType}过低";
                shouldAlarm = true;
            }

            if (shouldAlarm)
            {
                // 检查是否已经存在相同的活动报警，避免重复插入
                int existingAlarmId = await GetExistingAlarmIdAsync(alarmType, alarmMessage);
                if (existingAlarmId > 0)
                {
                    // 如果存在，则更新真实值和时间 (数据表没更新时间 只有创建时间)
                    await UpdateExistingAlarmAsync(existingAlarmId, currentValue.ToString(), alarmMessage);
                    InitAlarmList(); // 刷新当前报警列表
                }
                else
                {
                    await InsertAlarmAsync(alarmType, highLimit.ToString(), lowLimit.ToString(),
                                           currentValue.ToString(), alarmMessage, unit);
                    InitAlarmList(); // 刷新当前报警列表
                }

            }
            else
            {
                // 如果当前值正常，检查是否有需要恢复的报警
                await CheckAndRecoverAlarmsAsync(alarmType, currentValue);
                InitAlarmList(); // 刷新当前报警列表
            }
        }

        /// <summary>
        /// 检查并恢复已正常的报警
        /// </summary>
        private async Task CheckAndRecoverAlarmsAsync(string alarmType, double currentValue)
        {

            try
            {
                // 获取所有该类型的状态为0（活动）的报警
                string sql = @"SELECT alarm_id FROM alarm_info 
                      WHERE alarm_type = @alarmType 
                      AND alarm_status = 0";

                MySqlParameter[] parameters = {
                    new MySqlParameter("@alarmType", alarmType)
                };

                List<int> activeAlarmIds = await GetActiveAlarmIdsAsync(sql, parameters);

                foreach (int alarmId in activeAlarmIds)
                {
                    await RecoverAlarmAsync(alarmId, currentValue);
                }
            }
            catch (Exception ex)
            {

            }
        }

        /// <summary>
        /// 获取活动报警ID列表
        /// </summary>
        private async Task<List<int>> GetActiveAlarmIdsAsync(string sql, MySqlParameter[] parameters)
        {
            try
            {
                Func<IDataRecord, int> mapper = reader => Convert.ToInt32(reader["alarm_id"]);
                List<int> result = await Task.Run(() => MysqlHelper.ExecuteQuery<int>(sql, mapper, parameters));
                return result ?? new List<int>();
            }
            catch (Exception ex)
            {
                return new List<int>();
            }
        }

        /// <summary>
        /// 恢复报警（将状态改为1，设置恢复时间）
        /// </summary>
        private async Task RecoverAlarmAsync(int alarmId, double currentValue)
        {
            try
            {
                string sql = @"UPDATE alarm_info 
                      SET alarm_status = 1,
                          alarm_recovery_time = @recoveryTime,
                          alarm_real_value = @realValue
                      WHERE alarm_id = @alarmId";

                MySqlParameter[] parameters = {
                    new MySqlParameter("@recoveryTime", DateTime.Now),
                    new MySqlParameter("@alarmId", alarmId),
                    new MySqlParameter("@realValue", currentValue.ToString())
                };

                int affectedRows = await Task.Run(() => MysqlHelper.ExecuteNonQuery(sql, parameters));

                if (affectedRows > 0)
                {
                    LogHelper.Info(this.GetType(), $"[恢复报警]|报警已恢复 ID:{alarmId}", _currentUser?.UserAccount);
                }
            }
            catch (Exception ex)
            {
            }
        }


        /// <summary>
        /// 获取现有活动报警的ID
        /// </summary>
        private async Task<int> GetExistingAlarmIdAsync(string alarmType, string alarmMessage)
        {
            try
            {
                string sql = @"SELECT alarm_id FROM alarm_info 
                      WHERE alarm_type = @alarmType 
                      AND alarm_message = @alarmMessage 
                      AND alarm_status = 0 
                      ORDER BY alarm_create_time DESC 
                      LIMIT 1"; // 获取最新的活动报警

                MySqlParameter[] parameters = {
                    new MySqlParameter("@alarmType", alarmType),
                    new MySqlParameter("@alarmMessage", alarmMessage)
        };

                object result = await Task.Run(() => MysqlHelper.ExecuteScalar(sql, parameters));
                return result != null && result != DBNull.Value ? Convert.ToInt32(result) : 0;
            }
            catch (Exception ex)
            {
                LogHelper.Error(this.GetType(), "[获取报警ID]|获取现有报警ID时发生错误", ex, _currentUser?.UserAccount);
                return 0;
            }
        }

        /// <summary>
        /// 更新现有报警的真实值
        /// </summary>
        private async Task UpdateExistingAlarmAsync(int alarmId, string realValue, string alarmMessage)
        {
            try
            {
                string sql = @"UPDATE alarm_info 
                      SET alarm_real_value = @realValue, 
                          alarm_message = @alarmMessage 
                      WHERE alarm_id = @alarmId";

                MySqlParameter[] parameters = {
                    new MySqlParameter("@realValue", realValue),
                    new MySqlParameter("@alarmMessage", alarmMessage),
                    new MySqlParameter("@alarmId", alarmId)
        };

                await Task.Run(() => MysqlHelper.ExecuteNonQuery(sql, parameters));


            }
            catch (Exception ex)
            {

            }
        }

        /// <summary>
        /// 检查是否已存在相同的活动报警
        /// </summary>
        private async Task<bool> IsAlarmAlreadyExistsAsync(string alarmType, string alarmMessage)
        {
            try
            {
                string sql = @"SELECT COUNT(*) FROM alarm_info 
                      WHERE alarm_type = @alarmType 
                      AND alarm_message = @alarmMessage 
                      AND alarm_status = 0"; // 0表示活动报警

                MySqlParameter[] parameters = {
                    new MySqlParameter("@alarmType", alarmType),
                    new MySqlParameter("@alarmMessage", alarmMessage)
        };

                object result = await Task.Run(() => MysqlHelper.ExecuteScalar(sql, parameters));
                return Convert.ToInt32(result) > 0;
            }
            catch (Exception ex)
            {
                LogHelper.Error(this.GetType(), "[检查重复报警]|检查重复报警时发生错误", ex, _currentUser?.UserAccount);
                return false; // 出错时允许插入，避免漏报
            }
        }

        /// <summary>
        /// 插入报警记录到数据库
        /// </summary>
        private async Task InsertAlarmAsync(string alarmType, string highLimit, string lowLimit,
            string realValue, string alarmMessage, string unit)
        {
            try
            {
                string sql = @"INSERT INTO alarm_info 
                      (alarm_type, alarm_set_value, alarm_real_value, alarm_message, 
                       alarm_create_time, alarm_status) 
                      VALUES 
                      (@alarmType, @setValue, @realValue, @alarmMessage, @createTime, IFNULL(@alarmStatus, 0))";

                MySqlParameter[] parameters = {
                    new MySqlParameter("@alarmType", alarmType),
                    new MySqlParameter("@setValue", $"{lowLimit} - {highLimit}"), // 低限值-高限值   作为设定值显示
                    new MySqlParameter("@realValue", realValue),
                    new MySqlParameter("@alarmMessage", alarmMessage),
                    new MySqlParameter("@createTime", DateTime.Now),
                    new MySqlParameter("@alarmStatus", 0) // 0表示正在报警
                };

                await Task.Run(() => MysqlHelper.ExecuteNonQuery(sql, parameters));


                LogHelper.Info(this.GetType(), $"[插入报警]|报警已记录: {alarmType} - {alarmMessage} (实际值: {realValue}{unit})", _currentUser?.UserAccount);
            }
            catch (Exception ex)
            {
            }
        }

        /// <summary>
        /// 获取当前压力值
        /// </summary>
        private async Task<double> GetCurrentPressureAsync()
        {
            await Task.Delay(10); // 模拟延迟
            return new Random().NextDouble(); // 模拟数据
        }

        /// <summary>
        /// 获取当前温度值
        /// </summary>
        private async Task<double> GetCurrentTemperatureAsync()
        {
            await Task.Delay(10); // 模拟延迟
            return new Random().NextDouble(); // 模拟数据
        }

        /// <summary>
        /// 获取当前流量值
        /// </summary>
        private async Task<double> GetCurrentFlowAsync()
        {
            await Task.Delay(10); // 模拟延迟
            return new Random().NextDouble(); // 模拟数据
        }



        #endregion

        #region 导出报表
        private void ExecuteExport(object obj)
        {
            try
            {
                if (AlarmList == null || AlarmList.Count == 0)
                {
                    MsgBoxHelper.Info("没有数据可以导出");
                    return;
                }

                var saveFileDialog = new Microsoft.Win32.SaveFileDialog
                {
                    Filter = "Excel文件 (*.xlsx)|*.xlsx|所有文件 (*.*)|*.*",
                    FileName = $"报警记录_{DateTime.Now:yyyyMMdd_HHmmss}.xlsx"
                };

                if (saveFileDialog.ShowDialog() == true)
                {
                    // 使用通用的导出方法
                    var columnMappings = CreateAlarmColumnMappings();
                    ExcelExportHelper.ExportToExcel(AlarmList, columnMappings, saveFileDialog.FileName, "报警记录");

                    MsgBoxHelper.Info($"数据已成功导出到: {saveFileDialog.FileName}");
                    LogHelper.Info(this.GetType(), $"[导出Excel]|报警数据已导出到: {saveFileDialog.FileName}", _currentUser?.UserAccount);
                }
            }
            catch (Exception ex)
            {
                MsgBoxHelper.Error($"导出Excel失败: {ex.Message}");
                LogHelper.Error(this.GetType(), "[导出Excel]|导出报警数据到Excel失败", ex, _currentUser?.UserAccount);
            }
        }

        /// <summary>
        /// 创建报警数据的列映射
        /// </summary>
        /// <returns>报警数据列映射字典</returns>
        private Dictionary<string, string> CreateAlarmColumnMappings()
        {
            return new Dictionary<string, string>
            {
                { "AlarmId", "ID" },
                { "AlarmType", "报警类型" },
                { "AlarmSetValue", "报警设定值" },
                { "AlarmRealValue", "报警实际值" },
                { "AlarmMessage", "报警信息" },
                { "AlarmCreateTime", "报警产生时间" },
                { "AlarmRecoveryTime", "报警恢复时间" }
            };
        }

        #endregion
    }
}
